home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / rain_for.swf / scripts / __Packages / smashing / Viewport.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  2.4 KB  |  76 lines

  1. class smashing.Viewport
  2. {
  3.    static var centerY;
  4.    static var x;
  5.    static var halfWidth;
  6.    static var width;
  7.    static var halfHeight;
  8.    static var height;
  9.    static var centerX;
  10.    static var y;
  11.    static var startX;
  12.    static var startY;
  13.    static var z = 0;
  14.    static var focal = 1300;
  15.    function Viewport()
  16.    {
  17.    }
  18.    static function init(nWidth, nHeight)
  19.    {
  20.       if(nWidth == undefined)
  21.       {
  22.          nWidth = Stage.width;
  23.       }
  24.       if(nHeight == undefined)
  25.       {
  26.          nHeight = Stage.height;
  27.       }
  28.       Stage.scaleMode = "showAll";
  29.       smashing.Viewport.x = nWidth / 2;
  30.       smashing.Viewport.y = nHeight / 2;
  31.       smashing.Viewport.halfWidth = nWidth / 2;
  32.       smashing.Viewport.halfHeight = nHeight / 2;
  33.       smashing.Viewport.width = nWidth;
  34.       smashing.Viewport.height = nHeight;
  35.       smashing.Viewport.centerX = smashing.Viewport.x;
  36.       smashing.Viewport.centerY = smashing.Viewport.y;
  37.       smashing.Viewport.startX = smashing.Viewport.x;
  38.       smashing.Viewport.startY = smashing.Viewport.y;
  39.       Stage.scaleMode = "noScale";
  40.    }
  41.    static function getPos(o)
  42.    {
  43.       var _loc1_ = new smashing.RenderResult();
  44.       var _loc4_ = o.x - smashing.Viewport.x;
  45.       var _loc5_ = o.y - smashing.Viewport.y;
  46.       var _loc3_ = o.z - smashing.Viewport.z;
  47.       _loc1_.x = _loc4_;
  48.       o.mpX = _loc4_;
  49.       _loc1_.y = _loc5_;
  50.       o.mpY = _loc5_;
  51.       _loc1_.scale = smashing.Viewport.focal / (smashing.Viewport.focal + _loc3_);
  52.       o.mpZ = _loc3_;
  53.       return _loc1_;
  54.    }
  55.    static function localize(p)
  56.    {
  57.       return new smashing.Point3D(p.x - smashing.Viewport.x,p.y - smashing.Viewport.y,p.z - smashing.Viewport.z);
  58.    }
  59.    static function getFocal(p)
  60.    {
  61.       var _loc1_ = new smashing.Point3D(p.x - smashing.Viewport.x,p.y - smashing.Viewport.y,p.z - smashing.Viewport.z);
  62.       var _loc2_ = smashing.Viewport.focal / (smashing.Viewport.focal + _loc1_.z);
  63.       return new smashing.Point(_loc1_.x * _loc2_ + smashing.Viewport.centerX,_loc1_.y * _loc2_ + smashing.Viewport.centerY);
  64.    }
  65.    static function getScaleMod(zd)
  66.    {
  67.       return smashing.Viewport.focal / (smashing.Viewport.focal + zd);
  68.    }
  69.    static function reset()
  70.    {
  71.       smashing.Viewport.x = smashing.Viewport.startX;
  72.       smashing.Viewport.y = smashing.Viewport.startY;
  73.       smashing.Viewport.z = 0;
  74.    }
  75. }
  76.